package com.cazor.dg.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cazor.common.annotation.Log;
import com.cazor.common.core.controller.BaseController;
import com.cazor.common.core.domain.AjaxResult;
import com.cazor.common.enums.BusinessType;
import com.cazor.dg.domain.DgDeviceSensor;
import com.cazor.dg.service.IDgDeviceSensorService;
import com.cazor.common.utils.poi.ExcelUtil;
import com.cazor.common.core.page.TableDataInfo;

/**
 * 传感器Controller
 * 
 * @author cazor
 * @date 2023-11-25
 */
@RestController
@RequestMapping("/dg/dgDeviceSensor")
public class DgDeviceSensorController extends BaseController
{
    @Resource
    private IDgDeviceSensorService dgDeviceSensorService;

    /**
     * 查询传感器列表
     */
    @PreAuthorize("@ss.hasPermi('dg:dgDeviceSensor:list')")
    @GetMapping("/list")
    public TableDataInfo list(DgDeviceSensor dgDeviceSensor)
    {
        startPage();
        List<DgDeviceSensor> list = dgDeviceSensorService.selectDgDeviceSensorList(dgDeviceSensor);
        return getDataTable(list);
    }

    /**
     * 导出传感器列表
     */
    @PreAuthorize("@ss.hasPermi('dg:dgDeviceSensor:export')")
    @Log(title = "传感器", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DgDeviceSensor dgDeviceSensor)
    {
        List<DgDeviceSensor> list = dgDeviceSensorService.selectDgDeviceSensorList(dgDeviceSensor);
        ExcelUtil<DgDeviceSensor> util = new ExcelUtil<DgDeviceSensor>(DgDeviceSensor.class);
        util.exportExcel(response, list, "传感器数据");
    }

    /**
     * 获取传感器详细信息
     */
    @PreAuthorize("@ss.hasPermi('dg:dgDeviceSensor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dgDeviceSensorService.selectDgDeviceSensorById(id));
    }

    /**
     * 新增传感器
     */
    @PreAuthorize("@ss.hasPermi('dg:dgDeviceSensor:add')")
    @Log(title = "传感器", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DgDeviceSensor dgDeviceSensor)
    {
        return toAjax(dgDeviceSensorService.insertDgDeviceSensor(dgDeviceSensor));
    }

    /**
     * 修改传感器
     */
    @PreAuthorize("@ss.hasPermi('dg:dgDeviceSensor:edit')")
    @Log(title = "传感器", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DgDeviceSensor dgDeviceSensor)
    {
        return toAjax(dgDeviceSensorService.updateDgDeviceSensor(dgDeviceSensor));
    }

    /**
     * 删除传感器
     */
    @PreAuthorize("@ss.hasPermi('dg:dgDeviceSensor:remove')")
    @Log(title = "传感器", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dgDeviceSensorService.deleteDgDeviceSensorByIds(ids));
    }
}
